use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
use tokio::net::TcpStream;

#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum OutboundConfig {
    Direct,
    Socks5 {
        addr: SocketAddr,
        username: Option<String>,
        password: Option<String>,
    },
    Http {
        addr: SocketAddr,
        username: Option<String>,
        password: Option<String>,
    },
}

pub struct Outbound {
    config: OutboundConfig,
}

impl Outbound {
    pub fn new(config: OutboundConfig) -> Self {
        Self { config }
    }

    pub async fn connect(&self, target: &str) -> anyhow::Result<TcpStream> {
        match &self.config {
            OutboundConfig::Direct => {
                // Direct connection
                let stream = TcpStream::connect(target).await?;
                Ok(stream)
            }
            OutboundConfig::Socks5 { addr, username, password } => {
                // Connect through SOCKS5 proxy
                let mut stream = TcpStream::connect(addr).await?;
                
                // TODO: Implement SOCKS5 handshake
                // For now, just return the stream
                
                Ok(stream)
            }
            OutboundConfig::Http { addr, username, password } => {
                // Connect through HTTP proxy
                let stream = TcpStream::connect(addr).await?;
                
                // TODO: Implement HTTP CONNECT
                
                Ok(stream)
            }
        }
    }
}
